package org.example.config;

import java.io.IOException;
import java.io.Reader;
// 修正包导入
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

public class MybatisFactory {
    static SqlSessionFactory ssf=null;
    static SqlSession sqlSession;
    static{
        try {
            //加载配置文件
            Reader reader = Resources.getResourceAsReader("Mybatis-config.xml");
            //读取配置文件的流，创建会话工厂类
            ssf = new SqlSessionFactoryBuilder().build(reader);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }

    public static SqlSession  openSession(){
         sqlSession = ssf.openSession();
         return sqlSession;
    }

   
    
}
